package io.lckgroup.modules.lck.controller.wxgzh;

import io.lckgroup.common.utils.PageUtils;
import io.lckgroup.common.utils.R;
import io.lckgroup.modules.lck.annotation.WxLogin;
import io.lckgroup.modules.lck.annotation.WxLoginUser;
import io.lckgroup.modules.lck.entity.CommonCommentEntity;
import io.lckgroup.modules.lck.entity.CustomerInfoEntity;
import io.lckgroup.modules.lck.service.CommonCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/mp/wxgzhComment")
public class WxgzhCommentController {

    @Autowired
    private CommonCommentService commonCommentService;

    /**
     * 插入评价信息
     *
     * @param commonCommentEntity
     * @return
     */
    @PostMapping("/createComment")
    @WxLogin
    public R createComment(@RequestBody CommonCommentEntity commonCommentEntity) {
        int result = commonCommentService.createComment(commonCommentEntity);
        if (result == 1) {
            return R.ok();
        } else {
            return R.error("评论失败");
        }
    }

    /**
     * 根据审核状态分页查询评论
     *
     * @param params（包含分页参数和审核状态）
     * @param customerInfoEntity
     * @return
     */
    @GetMapping("/getCommentByState")
    @WxLogin
    public R getMyCommentByState(@RequestParam Map<String, Object> params, @WxLoginUser CustomerInfoEntity customerInfoEntity) {
        PageUtils list = commonCommentService.getMyCommentByState(params, customerInfoEntity);
        return R.ok().put("comment", list);
    }
    /**
     * 分页查询商家的评论列表
     */
    @RequestMapping("/merchantCommentList")
    public R merchantCommentList(@RequestParam Map<String, Object> params) {
        PageUtils page = commonCommentService.merchantCommentList(params);
        return R.ok().put("page", page);
    }
}
